
package org.argeproje.resim.ui.viewers;

import java.awt.Frame;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;



/**
 * This ImageView class shows how to use SWTImageCanvas to 
 * manipulate images. 
 * <p>
 * To facilitate the usage, you should setFocus to the canvas
 * at the beginning, and call the dispose at the end.
 * <p>
 */

public class ImageView extends ViewPart {
	public static final String ID = "org.argeproje.resim.ui.viewers.imageview"; 
		
	//protected ImageCanvas imageCanvas;
	protected Composite _composite;
	
	/**
	 * The constructor.
	 */
	public ImageView() {	
		super();
	}
	
	public void setViewerTitle(String newTitle)
	{
		setPartName(newTitle);
	}
	
	/**
	 * Create the GUI.
	 * @param frame The Composite handle of parent
	 */
	public void createPartControl(Composite parent) {
        _composite = new Composite(parent, SWT.EMBEDDED);
        _composite.setLayout(new FillLayout());   
	    /*
	  addListenerObject(new PaintListener() 
	  {
		public void paintControl(PaintEvent paintEvent) {
	      if(imageCanvas!=null) imageCanvas.repaint();
		}
	  });
	  */
	}
	
	public void setPanel(JPanel panel)
	{
		Frame frame = SWT_AWT.new_Frame(_composite);
		panel.setFocusable(true);
	    frame.add(new JScrollPane(panel));
	}

	/**
	 * Called when we must grab focus.
	 * @see org.eclipse.ui.part.ViewPart#setFocus
	 */
	public void setFocus() {
		//do nothing
	}

	/**
	 * Called when the View is to be disposed
	 */
	public void dispose() {
		_composite.dispose();
		super.dispose();
	}	
}